#include "sort.h"

void shellsort(char** data, int size) {

	int j, i, m;
	char* mid;
	for( m = size/2; m>0; m/=2 ) {
		for( j = m; j< size; j++ ) {
			for( i=j-m; i>=0; i-=m ) {
				if(stringcmp(data[i+m],data[i])>=0)
					break;
				else {
					mid = data[i];
					data[i] = data[i+m];
					data[i+m] = mid;
				}
			}
		}
	}
}

void bubblesort(char** data, int size) {

	int i, j;
	for (i = 0; i < size-1; i++) {
		for (j = 0; j < (size - (i + 1)); j++) {
			int result = stringcmp(data[j],data[j+1]);
			if (result > 0)
				swap(&data[j], &data[j+1]);
		}
	}
}

void swap(char** word1, char** word2) {
	char* tmp = *word1;
	*word1 = *word2;
	*word2 = tmp;
}
